<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
    

    

    



    <meta charset="utf-8">
    
    
    <meta name="sogou_site_verification" content="true">
    
    
    
    <title>遗传算法的基本概念和Java实现 | Lvshen&#39;s Blog | This is My World</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="算法,搜索">
    <meta name="baidu-site-verification" content="VIVNdSiMZm">
    <meta name="description" content="本文来自 Itimetraveler’s Blog： 遗传算法的基本概念和Java实现  基因遗传算法是一种灵感源于达尔文自然进化理论的启发式搜索算法。该算法反映了自然选择的过程，即最适者被选定繁殖，并产生下一代。本文简要地介绍了遗传算法的基本概念和实现，希望能为读者展示启发式搜索的魅力。 [">
<meta name="keywords" content="算法,搜索">
<meta property="og:type" content="article">
<meta property="og:title" content="遗传算法的基本概念和Java实现">
<meta property="og:url" content="https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/index.html">
<meta property="og:site_name" content="Lvshen&#39;s Blog">
<meta property="og:description" content="本文来自 Itimetraveler’s Blog： 遗传算法的基本概念和Java实现  基因遗传算法是一种灵感源于达尔文自然进化理论的启发式搜索算法。该算法反映了自然选择的过程，即最适者被选定繁殖，并产生下一代。本文简要地介绍了遗传算法的基本概念和实现，希望能为读者展示启发式搜索的魅力。 [">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://itimetraveler.github.io/gallery/genetic-algorithms/1-BYDJpa6M2rzWNSurvspf8Q.png">
<meta property="og:image" content="https://itimetraveler.github.io/gallery/genetic-algorithms/1-vIrsxg12DSltpdWoO561yA.png">
<meta property="og:image" content="https://itimetraveler.github.io/gallery/genetic-algorithms/1-Wi6ou9jyMHdxrF2dgczz7g.png">
<meta property="og:image" content="https://itimetraveler.github.io/gallery/genetic-algorithms/1-eQxFezBtdfdLxHsvSvBNGQ.png">
<meta property="og:image" content="https://itimetraveler.github.io/gallery/genetic-algorithms/1-_Dl6Hwkay-UU24DJ_oVrLw.png">
<meta property="og:image" content="https://itimetraveler.github.io/gallery/genetic-algorithms/1-CGt_UhRqCjIDb7dqycmOAg.png">
<meta property="og:updated_time" content="2017-08-28T01:33:45.424Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="遗传算法的基本概念和Java实现">
<meta name="twitter:description" content="本文来自 Itimetraveler’s Blog： 遗传算法的基本概念和Java实现  基因遗传算法是一种灵感源于达尔文自然进化理论的启发式搜索算法。该算法反映了自然选择的过程，即最适者被选定繁殖，并产生下一代。本文简要地介绍了遗传算法的基本概念和实现，希望能为读者展示启发式搜索的魅力。 [">
<meta name="twitter:image" content="https://itimetraveler.github.io/gallery/genetic-algorithms/1-BYDJpa6M2rzWNSurvspf8Q.png">
    
    <link rel="shortcut icon" href="/img/mylogo.jpg">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">我的技术小房间</h5>
          <a href="mailto:https://lvshen9.github.io" title="https://lvshen9.github.io" class="mail">https://lvshen9.github.io</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                Categories
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/about"  >
                <i class="icon icon-lg icon-address-book"></i>
                About
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/collection"  >
                <i class="icon icon-lg icon-apple"></i>
                Collection
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://lvshen9.github.io/" target="_blank" >
                <i class="icon icon-lg icon-wordpress"></i>
                Blog
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/lvshen9" target="_blank" >
                <i class="icon icon-lg icon-github-alt"></i>
                GitHub
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">遗传算法的基本概念和Java实现</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">遗传算法的基本概念和Java实现</h1>
        <h5 class="subtitle">
            
                <time datetime="2017-08-28T01:24:57.000Z" itemprop="datePublished" class="page-time">
  2017-08-28
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/技术/">技术</a></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#遗传算法的概念"><span class="post-toc-number">1.</span> <span class="post-toc-text">遗传算法的概念**</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#初始化"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">初始化</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#个体评价（计算适应度函数）"><span class="post-toc-number">1.2.</span> <span class="post-toc-text">个体评价（计算适应度函数）</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#选择运算"><span class="post-toc-number">1.3.</span> <span class="post-toc-text">选择运算</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#交叉运算"><span class="post-toc-number">1.4.</span> <span class="post-toc-text">交叉运算</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#变异运算"><span class="post-toc-number">1.5.</span> <span class="post-toc-text">变异运算</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#终止"><span class="post-toc-number">1.6.</span> <span class="post-toc-text">终止</span></a></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#案例实现"><span class="post-toc-number">2.</span> <span class="post-toc-text">案例实现</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#Java-中的实例实现"><span class="post-toc-number">2.1.</span> <span class="post-toc-text">Java 中的实例实现</span></a></li></ol></li></ol>
        </nav>
    </aside>


<article id="post-遗传算法的基本概念和Java实现"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">遗传算法的基本概念和Java实现</h1>
        <div class="post-meta">
            <time class="post-time" title="2017-08-28 09:24:57" datetime="2017-08-28T01:24:57.000Z"  itemprop="datePublished">2017-08-28</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/技术/">技术</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <blockquote>
<p>本文来自 Itimetraveler’s Blog： <a href="https://itimetraveler.github.io/2017/07/11/%E9%81%97%E4%BC%A0%E7%AE%97%E6%B3%95%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5%E5%92%8CJava%E5%AE%9E%E7%8E%B0/" target="_blank" rel="noopener">遗传算法的基本概念和Java实现</a></p>
</blockquote>
<p>基因遗传算法是一种灵感源于达尔文自然进化理论的启发式搜索算法。该算法反映了自然选择的过程，即最适者被选定繁殖，并产生下一代。本文简要地介绍了遗传算法的基本概念和实现，希望能为读者展示启发式搜索的魅力。</p>
<p>[<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://itimetraveler.github.io/gallery/genetic-algorithms/1-BYDJpa6M2rzWNSurvspf8Q.png" alt="如上图（左）所示，遗传算法的个体由多条染色体组成，每条染色体由多个基因组成。上图（右）展示了染色体分割和组合的方式。](https://itimetraveler.github.io/gallery/genetic-algorithms/1-BYDJpa6M2rzWNSurvspf8Q.png)" title>
                </div>
                <div class="image-caption">如上图（左）所示，遗传算法的个体由多条染色体组成，每条染色体由多个基因组成。上图（右）展示了染色体分割和组合的方式。](https://itimetraveler.github.io/gallery/genetic-algorithms/1-BYDJpa6M2rzWNSurvspf8Q.png)</div>
            </figure></p>
<a id="more"></a>
<h3 id="遗传算法的概念"><a href="#遗传算法的概念" class="headerlink" title="遗传算法的概念**"></a>遗传算法的概念**</h3><p>自然选择的过程从选择群体中最适应环境的个体开始。后代继承了父母的特性，并且这些特性将添加到下一代中。如果父母具有更好的适应性，那么它们的后代将更易于存活。迭代地进行该自然选择的过程，最终，我们将得到由最适应环境的个体组成的一代。</p>
<p>这一概念可以被应用于搜索问题中。我们考虑一个问题的诸多解决方案，并从中搜寻出最佳方案。</p>
<p>遗传算法含以下五步：</p>
<ol>
<li>初始化</li>
<li>个体评价（计算适应度函数）</li>
<li>选择运算</li>
<li>交叉运算</li>
<li>变异运算</li>
</ol>
<h4 id="初始化"><a href="#初始化" class="headerlink" title="初始化"></a><strong>初始化</strong></h4><p>该过程从种群的一组个体开始，且每一个体都是待解决问题的一个候选解。</p>
<p>个体以一组参数（变量）为特征，这些特征被称为基因，串联这些基因就可以组成染色体（问题的解）。</p>
<p>在遗传算法中，单个个体的基因组以字符串的方式呈现，通常我们可以使用二进制（1 和 0 的字符串）编码，即一个二进制串代表一条染色体串。因此可以说我们将基因串或候选解的特征编码在染色体中。</p>
<p>[<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://itimetraveler.github.io/gallery/genetic-algorithms/1-vIrsxg12DSltpdWoO561yA.png" alt="*种群、染色体和基因*](https://itimetraveler.github.io/gallery/genetic-algorithms/1-vIrsxg12DSltpdWoO561yA.png)" title>
                </div>
                <div class="image-caption">*种群、染色体和基因*](https://itimetraveler.github.io/gallery/genetic-algorithms/1-vIrsxg12DSltpdWoO561yA.png)</div>
            </figure></p>
<h4 id="个体评价（计算适应度函数）"><a href="#个体评价（计算适应度函数）" class="headerlink" title="个体评价（计算适应度函数）"></a><strong>个体评价（计算适应度函数）</strong></h4><p>个体评价利用适应度函数评估了该个体对环境的适应度（与其它个体竞争的能力）。每一个体都有适应度评分，个体被选中进行繁殖的可能性取决于其适应度评分。适应度函数值越大，解的质量就越高。适应度函数是遗传算法进化的驱动力，也是进行自然选择的唯一标准，它的设计应结合求解问题本身的要求而定。</p>
<h4 id="选择运算"><a href="#选择运算" class="headerlink" title="选择运算"></a><strong>选择运算</strong></h4><p>选择运算的目的是选出适应性最好的个体，并使它们将基因传到下一代中。基于其适应度评分，我们选择多对较优个体（父母）。适应度高的个体更易被选中繁殖，即将较优父母的基因传递到下一代。</p>
<h4 id="交叉运算"><a href="#交叉运算" class="headerlink" title="交叉运算"></a><strong>交叉运算</strong></h4><p>交叉运算是遗传算法中最重要的阶段。对每一对配对的父母，基因都存在随机选中的交叉点。</p>
<p>举个例子，下图的交叉点为 3：</p>
<p>[<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://itimetraveler.github.io/gallery/genetic-algorithms/1-Wi6ou9jyMHdxrF2dgczz7g.png" alt="Crossover point](https://itimetraveler.github.io/gallery/genetic-algorithms/1-Wi6ou9jyMHdxrF2dgczz7g.png)" title>
                </div>
                <div class="image-caption">Crossover point](https://itimetraveler.github.io/gallery/genetic-algorithms/1-Wi6ou9jyMHdxrF2dgczz7g.png)</div>
            </figure></p>
<p>父母间在交叉点之前交换基因，从而产生了后代。</p>
<p>[<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://itimetraveler.github.io/gallery/genetic-algorithms/1-eQxFezBtdfdLxHsvSvBNGQ.png" alt="Exchanging genes among parents](https://itimetraveler.github.io/gallery/genetic-algorithms/1-eQxFezBtdfdLxHsvSvBNGQ.png)" title>
                </div>
                <div class="image-caption">Exchanging genes among parents](https://itimetraveler.github.io/gallery/genetic-algorithms/1-eQxFezBtdfdLxHsvSvBNGQ.png)</div>
            </figure></p>
<p>父母间交换基因，然后产生的新后代被添加到种群中。</p>
<p>[<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://itimetraveler.github.io/gallery/genetic-algorithms/1-_Dl6Hwkay-UU24DJ_oVrLw.png" alt="New offspring](https://itimetraveler.github.io/gallery/genetic-algorithms/1-_Dl6Hwkay-UU24DJ_oVrLw.png)" title>
                </div>
                <div class="image-caption">New offspring](https://itimetraveler.github.io/gallery/genetic-algorithms/1-_Dl6Hwkay-UU24DJ_oVrLw.png)</div>
            </figure></p>
<h4 id="变异运算"><a href="#变异运算" class="headerlink" title="变异运算"></a><strong>变异运算</strong></h4><p>在某些形成的新后代中，它们的某些基因可能受到低概率变异因子的作用。这意味着二进制位串中的某些位可能会翻转。</p>
<p>[<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://itimetraveler.github.io/gallery/genetic-algorithms/1-CGt_UhRqCjIDb7dqycmOAg.png" alt="变异运算前后](https://itimetraveler.github.io/gallery/genetic-algorithms/1-CGt_UhRqCjIDb7dqycmOAg.png)" title>
                </div>
                <div class="image-caption">变异运算前后](https://itimetraveler.github.io/gallery/genetic-algorithms/1-CGt_UhRqCjIDb7dqycmOAg.png)</div>
            </figure></p>
<p>变异运算可用于保持种群内的多样性，并防止过早收敛。</p>
<h4 id="终止"><a href="#终止" class="headerlink" title="终止"></a><strong>终止</strong></h4><p>在群体收敛的情况下（群体内不产生与前一代差异较大的后代）该算法终止。也就是说遗传算法提供了一组问题的解。</p>
<h3 id="案例实现"><a href="#案例实现" class="headerlink" title="案例实现"></a><strong>案例实现</strong></h3><p>种群的规模恒定。新一代形成时，适应度最差的个体凋亡，为后代留出空间。这些阶段的序列被不断重复，以产生优于先前的新一代。</p>
<p>这一迭代过程的伪代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">START</span><br><span class="line">Generate the initial population</span><br><span class="line">Compute fitness</span><br><span class="line">REPEAT</span><br><span class="line">    Selection</span><br><span class="line">    Crossover</span><br><span class="line">    Mutation</span><br><span class="line">    Compute fitness</span><br><span class="line">UNTIL population has converged</span><br><span class="line">STOP</span><br></pre></td></tr></table></figure>
<h4 id="Java-中的实例实现"><a href="#Java-中的实例实现" class="headerlink" title="Java 中的实例实现"></a><strong>Java 中的实例实现</strong></h4><p>以下展示的是遗传算法在 Java 中的示例实现，我们可以随意调试和修改这些代码。给定一组五个基因，每一个基因可以保存一个二进制值 0 或 1。这里的适应度是基因组中 1 的数量。如果基因组内共有五个 1，则该个体适应度达到最大值。如果基因组内没有 1，那么个体的适应度达到最小值。该遗传算法希望最大化适应度，并提供适应度达到最大的个体所组成的群体。注意：本例中，在交叉运算与突变运算之后，适应度最低的个体被新的，适应度最高的后代所替代。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.Random;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> Vijini</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//Main class</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SimpleDemoGA</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    Population population = <span class="keyword">new</span> Population();</span><br><span class="line">    Individual fittest;</span><br><span class="line">    Individual secondFittest;</span><br><span class="line">    <span class="keyword">int</span> generationCount = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        Random rn = <span class="keyword">new</span> Random();</span><br><span class="line">        </span><br><span class="line">        SimpleDemoGA demo = <span class="keyword">new</span> SimpleDemoGA();</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//Initialize population</span></span><br><span class="line">        demo.population.initializePopulation(<span class="number">10</span>);</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//Calculate fitness of each individual</span></span><br><span class="line">        demo.population.calculateFitness();</span><br><span class="line">        </span><br><span class="line">        System.out.println(<span class="string">"Generation: "</span> + demo.generationCount + <span class="string">" Fittest: "</span> + demo.population.fittest);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//While population gets an individual with maximum fitness</span></span><br><span class="line">        <span class="keyword">while</span> (demo.population.fittest &lt; <span class="number">5</span>) &#123;</span><br><span class="line">            ++demo.generationCount;</span><br><span class="line">            </span><br><span class="line">            <span class="comment">//Do selection</span></span><br><span class="line">            demo.selection();</span><br><span class="line">            </span><br><span class="line">            <span class="comment">//Do crossover</span></span><br><span class="line">            demo.crossover();</span><br><span class="line">            </span><br><span class="line">            <span class="comment">//Do mutation under a random probability</span></span><br><span class="line">            <span class="keyword">if</span> (rn.nextInt()%<span class="number">7</span> &lt; <span class="number">5</span>) &#123;</span><br><span class="line">                demo.mutation();</span><br><span class="line">            &#125;</span><br><span class="line">            </span><br><span class="line">            <span class="comment">//Add fittest offspring to population</span></span><br><span class="line">            demo.addFittestOffspring();</span><br><span class="line">            </span><br><span class="line">            <span class="comment">//Calculate new fitness value </span></span><br><span class="line">            demo.population.calculateFitness();</span><br><span class="line">            </span><br><span class="line">            System.out.println(<span class="string">"Generation: "</span> + demo.generationCount + <span class="string">" Fittest: "</span> + demo.population.fittest);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        System.out.println(<span class="string">"\nSolution found in generation "</span> + demo.generationCount);</span><br><span class="line">        System.out.println(<span class="string">"Fitness: "</span>+demo.population.getFittest().fitness);</span><br><span class="line">        System.out.print(<span class="string">"Genes: "</span>);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;</span><br><span class="line">            System.out.print(demo.population.getFittest().genes[i]);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        System.out.println(<span class="string">""</span>);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Selection</span></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">selection</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//Select the most fittest individual</span></span><br><span class="line">        fittest = population.getFittest();</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//Select the second most fittest individual</span></span><br><span class="line">        secondFittest = population.getSecondFittest();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Crossover</span></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">crossover</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        Random rn = <span class="keyword">new</span> Random();</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//Select a random crossover point</span></span><br><span class="line">        <span class="keyword">int</span> crossOverPoint = rn.nextInt(population.individuals[<span class="number">0</span>].geneLength);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//Swap values among parents</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; crossOverPoint; i++) &#123;</span><br><span class="line">            <span class="keyword">int</span> temp = fittest.genes[i];</span><br><span class="line">            fittest.genes[i] = secondFittest.genes[i];</span><br><span class="line">            secondFittest.genes[i] = temp;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Mutation</span></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">mutation</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        Random rn = <span class="keyword">new</span> Random();</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//Select a random mutation point</span></span><br><span class="line">        <span class="keyword">int</span> mutationPoint = rn.nextInt(population.individuals[<span class="number">0</span>].geneLength);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//Flip values at the mutation point</span></span><br><span class="line">        <span class="keyword">if</span> (fittest.genes[mutationPoint] == <span class="number">0</span>) &#123;</span><br><span class="line">            fittest.genes[mutationPoint] = <span class="number">1</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            fittest.genes[mutationPoint] = <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        mutationPoint = rn.nextInt(population.individuals[<span class="number">0</span>].geneLength);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (secondFittest.genes[mutationPoint] == <span class="number">0</span>) &#123;</span><br><span class="line">            secondFittest.genes[mutationPoint] = <span class="number">1</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            secondFittest.genes[mutationPoint] = <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Get fittest offspring</span></span><br><span class="line">    <span class="function">Individual <span class="title">getFittestOffspring</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (fittest.fitness &gt; secondFittest.fitness) &#123;</span><br><span class="line">            <span class="keyword">return</span> fittest;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> secondFittest;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">//Replace least fittest individual from most fittest offspring</span></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">addFittestOffspring</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//Update fitness values of offspring</span></span><br><span class="line">        fittest.calcFitness();</span><br><span class="line">        secondFittest.calcFitness();</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//Get index of least fit individual</span></span><br><span class="line">        <span class="keyword">int</span> leastFittestIndex = population.getLeastFittestIndex();</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//Replace least fittest individual from most fittest offspring</span></span><br><span class="line">        population.individuals[leastFittestIndex] = getFittestOffspring();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//Individual class</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Individual</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">int</span> fitness = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">int</span>[] genes = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">5</span>];</span><br><span class="line">    <span class="keyword">int</span> geneLength = <span class="number">5</span>;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">Individual</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        Random rn = <span class="keyword">new</span> Random();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//Set genes randomly for each individual</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; genes.length; i++) &#123;</span><br><span class="line">            genes[i] = rn.nextInt() % <span class="number">2</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        fitness = <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Calculate fitness</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">calcFitness</span><span class="params">()</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        fitness = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;</span><br><span class="line">            <span class="keyword">if</span> (genes[i] == <span class="number">1</span>) &#123;</span><br><span class="line">                ++fitness;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//Population class</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Population</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">int</span> popSize = <span class="number">10</span>;</span><br><span class="line">    Individual[] individuals = <span class="keyword">new</span> Individual[<span class="number">10</span>];</span><br><span class="line">    <span class="keyword">int</span> fittest = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Initialize population</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">initializePopulation</span><span class="params">(<span class="keyword">int</span> size)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; individuals.length; i++) &#123;</span><br><span class="line">            individuals[i] = <span class="keyword">new</span> Individual();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Get the fittest individual</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Individual <span class="title">getFittest</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> maxFit = Integer.MIN_VALUE;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; individuals.length; i++) &#123;</span><br><span class="line">            <span class="keyword">if</span> (maxFit &lt;= individuals[i].fitness) &#123;</span><br><span class="line">                maxFit = i;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        fittest = individuals[maxFit].fitness;</span><br><span class="line">        <span class="keyword">return</span> individuals[maxFit];</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Get the second most fittest individual</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Individual <span class="title">getSecondFittest</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> maxFit1 = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> maxFit2 = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; individuals.length; i++) &#123;</span><br><span class="line">            <span class="keyword">if</span> (individuals[i].fitness &gt; individuals[maxFit1].fitness) &#123;</span><br><span class="line">                maxFit2 = maxFit1;</span><br><span class="line">                maxFit1 = i;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (individuals[i].fitness &gt; individuals[maxFit2].fitness) &#123;</span><br><span class="line">                maxFit2 = i;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> individuals[maxFit2];</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Get index of least fittest individual</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getLeastFittestIndex</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> minFit = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; individuals.length; i++) &#123;</span><br><span class="line">            <span class="keyword">if</span> (minFit &gt;= individuals[i].fitness) &#123;</span><br><span class="line">                minFit = i;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> minFit;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Calculate fitness of each individual</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">calculateFitness</span><span class="params">()</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; individuals.length; i++) &#123;</span><br><span class="line">            individuals[i].calcFitness();</span><br><span class="line">        &#125;</span><br><span class="line">        getFittest();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>原文来自：<a href="https://medium.com/towards-data-science/introduction-to-genetic-algorithms-including-example-code-e396e98d8bf3" target="_blank" rel="noopener">Introduction to Genetic Algorithms — Including Example Code</a></p>
</blockquote>

        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2017-08-28T01:33:45.424Z" itemprop="dateUpdated">2017-08-28 09:33:45</time>
</span><br>


        
        原文链接：<a href="/2017/08/28/遗传算法的基本概念和Java实现/" target="_blank" rel="external">https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/</a>
        
    </div>
    
    <footer>
        <a href="https://lvshen9.gitee.io">
            <img src="/img/avatar.jpg" alt="我的技术小房间">
            我的技术小房间
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/搜索/">搜索</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/算法/">算法</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/&title=《遗传算法的基本概念和Java实现》 — Lvshen's Blog&pic=https://lvshen9.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/&title=《遗传算法的基本概念和Java实现》 — Lvshen's Blog&source=
本文来自 Itimetraveler’s Blog： 遗传算法的基本概念和Java实现

基因遗传算法是一种灵感源于达尔文自然进化理论的启发式搜索算法。..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《遗传算法的基本概念和Java实现》 — Lvshen's Blog&url=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/&via=https://lvshen9.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2017/08/29/如何在MySQL中使用索引/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">如何在MySQL中使用索引</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2017/08/27/bitmap/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">【算法】10亿int型数，统计只出现一次的数</h4>
      </a>
    </div>
  
</nav>



    











    <!-- Valine Comments -->
    <div class="comments vcomment" id="comments"></div>
    <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
    <script src="//unpkg.com/valine@latest/dist/Valine.min.js"></script>
    <!-- Valine Comments script -->
    <script>
        var GUEST_INFO = ['nick','mail','link'];
        var guest_info = 'nick,mail,link'.split(',').filter(function(item){
          return GUEST_INFO.indexOf(item) > -1
        });
        new Valine({
            el: '#comments',
            notify: 'false' == 'true',
            verify: 'false' == 'true',
            appId: "dy9kXHwg5jQUlLryQmpjWRlM-gzGzoHsz",
            appKey: "P9Nh39Ol0JbMMiYqNGHEP3ml",
            avatar: "mm",
            placeholder: "Just go go",
            guest_info: guest_info.length == 0 ? GUEST_INFO : guest_info,
            pageSize: "10"
        })
    </script>
    <!-- Valine Comments end -->







</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        谢谢大爷~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="https://lvshen9.github.io/blog2/pay/weixin.jpg" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check"
                data-wechat="https://lvshen9.github.io/blog2/pay/weixin.jpg" data-alipay="https://lvshen9.github.io/blog2/pay/zhifu.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
            <span>博客内容遵循 <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>我的技术小房间 &copy; 2015 - 2020</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/&title=《遗传算法的基本概念和Java实现》 — Lvshen's Blog&pic=https://lvshen9.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/&title=《遗传算法的基本概念和Java实现》 — Lvshen's Blog&source=
本文来自 Itimetraveler’s Blog： 遗传算法的基本概念和Java实现

基因遗传算法是一种灵感源于达尔文自然进化理论的启发式搜索算法。..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《遗传算法的基本概念和Java实现》 — Lvshen's Blog&url=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/&via=https://lvshen9.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=https://lvshen9.gitee.io/2017/08/28/遗传算法的基本概念和Java实现/" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
